package org.scs.carleton.ca.pgdt.core.internal.parser;

import java.util.List;

import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTArgument;
import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTFunctor;
import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTStructure;
import org.scs.carleton.ca.pgdt.core.visitor.PrologVisitor;

/**
 * The physical node for a structure.  This should not be used externally.
 * 
 * @author tessierj
 *
 */
public class ASTStructure extends ASTNode implements IASTStructure {
	private IASTFunctor functor;
	private List<IASTArgument> terms;
	
	public ASTStructure(ASTTranslationUnit translationUnit, int type, IASTFunctor functor, List<IASTArgument> arguments) {
		super(translationUnit, type);
		this.functor = functor;
		this.terms = arguments;
	}

	@Override
	public IASTFunctor getFunctor() {
		return functor;
	}

	@Override
	public List<IASTArgument> getTerms() {
		return terms;
	}
	
	@SuppressWarnings("nls")
	public String toString() {
		return "Structure from " + getStartOffset() + " to " + getEndOffset();
	}
	
	@Override
	public boolean accept(PrologVisitor visitor) {
		boolean visitChildren = visitor.visit(this);
		
		if (visitor.visit(this)) {
			//If the visitor wants to visit this node...
			functor.accept(visitor);
			for (IASTArgument node : terms) {
				node.accept(visitor);
			}
		}
		
		return visitChildren;
	}
}
